<?php

namespace app\admin\service\channel;

use tmcore\base\BaseService;
use app\common\model\setting\Config as ConfigModel;
use tmcore\services\ConfigService;

class WxopenService extends BaseService
{
    /**
     * 获取微信开放平台渠道配置
     * @return array
     */
    public static function getWxopenConfig(): array
    {
        $config = com_get_config( 'wx_op_channel','sys');
        return [
            'app_id' => $config['app_id'] ?? '',
            'app_secret' => $config['app_secret'] ?? '',
        ];
    }

    /**
     * 设置微信开放平台渠道配置
     * @param array $params
     * @return bool
     */
    public static function setWxopenConfig(array $params)
    {
        $data = [
            'app_id' => $params['app_id']??'', // appId
            'app_secret' => $params['app_secret']??'', // appSecret
        ];

        $res = ConfigModel::where(['name' => 'wx_op_channel'])->update(['value' => json_encode($data, 320)]);

        (new ConfigService)->setConfig('create', 'sys', 'wx_op_channel');

        return $res !== false;
    }
}